﻿using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Drawing;
using System.Linq;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;


using IssueTracker.Business.Entity;
using IssueTracker.Business.BO;

namespace IssueTracker.Workflow.Activities
{
    [Designer(typeof(StateChangedDesigner), typeof(IDesigner))]
    public partial class IssueProcessStarted : System.Workflow.ComponentModel.Activity
	{
		public IssueProcessStarted()
		{
			InitializeComponent();
		}

        #region Execution Logic

        protected override ActivityExecutionStatus Execute(ActivityExecutionContext context)
        {
            UpdateWorkflowId((Issue)base.GetValue(ReportedIssueProperty));

            return ActivityExecutionStatus.Closed;
        }

        private void UpdateWorkflowId(Issue issue)
        {
            IssueBO issueBo = new IssueBO();
            issue.WfWorkflowId = this.WorkflowInstanceId ;
            
            try
            {
                issueBo.AddNew(issue);
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }

        #endregion

        #region Properties

        public static DependencyProperty ReportedIssueProperty = DependencyProperty.Register("ReportedIssue", typeof(IssueTracker.Business.Entity.Issue), typeof(IssueProcessStarted));

        [Description("Reported Issue")]
        [Browsable(true)]
        [Category("Issue")]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
        public IssueTracker.Business.Entity.Issue ReportedIssue
        {
            set { base.SetValue(ReportedIssueProperty, value); }
            get { return (Issue)base.GetValue(ReportedIssueProperty); }
        }
        #endregion
    }
}
